package com.platform.modular.controller;

import com.platform.common.model.Result;
import com.platform.modular.feign.account.MerchantAccountFeignService;
import com.platform.modular.feign.car.MerchantModelFeignService;
import com.platform.modular.model.account.vo.AdviserDetailVO;
import com.platform.modular.model.account.vo.MyAdviserVO;
import com.platform.modular.model.account.vo.PersonalCenterDetailVO;
import com.platform.modular.model.car.dto.MerchantModelListDTO;
import com.platform.modular.model.car.vo.MerchantModelVO;
import com.platform.modular.util.MiniprogramUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author yifei.han
 * @version 1.0
 * @className PersonalCenterController
 * @description 个人中心
 * @date 2022/3/16
 */
@Slf4j
@RestController
@RequestMapping(value = "/miniprogram/personalCenter")
public class PersonalCenterController {

    @Autowired
    private MiniprogramUtil miniprogramUtil;

    @Autowired
    private MerchantAccountFeignService merchantAccountFeignService;

    @Autowired
    private MerchantModelFeignService merchantModelFeignService;

    /**
     * 个人中心
     * @param request
     * @return
     */
    @RequestMapping(value = "/personalCenterDetail")
    public Result personalCenterDetail(HttpServletRequest request) {
        Long merchantId = miniprogramUtil.obtainMerchantId(request);
        Long accountId = miniprogramUtil.obtainAccountId(request);
        PersonalCenterDetailVO personalCenterDetail = merchantAccountFeignService.miniprogramPersonalCenterDetail(accountId, merchantId);
        return Result.ok().setResult(personalCenterDetail);
    }

    /**
     * 我的顾问
     * @param request
     * @return
     */
    @RequestMapping(value = "/myAdviser")
    public Result myAdviser(HttpServletRequest request) {
        Long merchantId = miniprogramUtil.obtainMerchantId(request);
        Long accountId = miniprogramUtil.obtainAccountId(request);
        MyAdviserVO myAdviser = merchantAccountFeignService.obtainMyAdviser(accountId, merchantId);
        return Result.ok().setResult(myAdviser);
    }

    /**
     * 顾问详情
     * @param adviserId
     * @return
     */
    @RequestMapping(value = "/obtainAdviserDetail")
    public Result obtainAdviserDetail(Long adviserId) {
        AdviserDetailVO adviserDetail = merchantAccountFeignService.obtainAdviserDetail(adviserId);
        MerchantModelListDTO merchantModelListDTO = new MerchantModelListDTO();
        merchantModelListDTO.setPageNo(1);
        merchantModelListDTO.setPageSize(10);
        List<MerchantModelVO> merchantModelList = merchantModelFeignService.miniprogramMerchantModelList(merchantModelListDTO);
        adviserDetail.setMerchantModelList(merchantModelList);
        return Result.ok().setResult(adviserDetail);
    }





}
